﻿using Yitter.IdGenerator;

namespace OrderingFoot.Core.Tool
{
    /// <summary>
    /// 唯一ID生成器
    /// </summary>
    public sealed class IdGenerator
    {
        /// <summary>
        /// 
        /// </summary>
        private static readonly IdGenerator _idGenerator = new IdGenerator();

        /// <summary>
        /// ctor
        /// </summary>
        private IdGenerator()
        {
            var options = new IdGeneratorOptions(CommonData.WorkId)
            {
                WorkerIdBitLength = CommonData.WorkerBitLength
            };
            YitIdHelper.SetIdGenerator(options);
        }

        /// <summary>
        /// 获取实例
        /// </summary>
        public static IdGenerator Instance { get { return _idGenerator; } }

        /// <summary>
        /// 获取id
        /// </summary>
        public long GetNexId()
        {
            return YitIdHelper.NextId();
        }
    }
}
